package com.example.demo.service;

import java.util.List;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import com.example.demo.entity.User;
import com.example.demo.repository.UserRepository;

@Service
public class UserService {

	@Resource
	private UserRepository userRepository;
	
	@Transactional
	public User addUser(User user) {
		return userRepository.save(user);
	}
	
	@Transactional
	public void remove(Integer id) {
		userRepository.delete(id);
	}
	
	public User getUser(Integer id) {
		return userRepository.findOne(id);
	}
	
	public List<User> getByName(String name) {
		return userRepository.getByName(name);
	}
	
	
}
